//package points24;
import java.util.*;

public class myper2
{
	int col;
	int row;
	public int [][]data;

	private int factorial(int n)
	{
		int r=1;
		if (n<=1) return 1;
		for(int i=n;i>1;i--)
			r*=i;
		return r;

	}

	public myper2(int pcol)
	{
		col=pcol;
		row=factorial(col);
		System.out.println(col);
		System.out.println(row);
		data=new int[row][col];
		//System.out.println( "Done in constructor");


	}

	public void dump()
	{
		for(int i=0;i<row;i++)
		{
			for(int j=0;j<col;j++)
			{
				 System.out.print(data[i][j]+" ");

			}
			 System.out.println();
		}

	}

	public void generate()
	{

		//System.out.println( "initializing ...");
		data[0][0]=1; // initialize first level, trivial

		// 1 represents level 1
		for(int cl=1;cl<col;cl++) // expanded level by level
		{
			System.out.print("Current level");
			System.out.println(cl);
			int nl=cl+1;
			int lastrowcl=factorial(cl);
			int lastrownl=factorial(nl);

			int crnl=lastrownl-1; //current row of next level for duplication
			//In the current table, for each row starting from the bottom row,
			for(int crfd=lastrowcl-1; crfd>=0;crfd--) // current row for duplication
			{
				//duplicate it next level times while weaving in the next number
				//three parts with the middle part is the level+1

				for(int d=1;d<=nl;d++, crnl--)
				{
					int which;
					// part 1; the left part
					for(which=0;which<d-1;which++)
						data[crnl][which]=data[crfd][which]; //copy

					System.out.println(crnl);
					System.out.println(which);
					// part 2; the new number
					data[crnl][d-1]=nl;

					//part 3; the remaining part
					for(which=d;which<nl;which++)
						data[crnl][which]=data[crfd][which-1]; //copy



				}


			}

		}


	}

} // end of the class myper2


